'''This file deals with playing audio within the game. They perform checks to
see if pygame.mixer is initialized before playing anything.

This library keeps track of previously loaded sounds to avoid loading of
multiple instances of the same sound.'''

from pygame import mixer

sound_list = {}

def load_sound(file_name):
    '''Loads and returns a sound from a file, if pygame.mixer has been
    initialized.'''
    global sound_list
    if mixer.get_init() and file_name:
        if not sound_list.has_key(file_name):
            sound_list[file_name] = mixer.Sound(file_name)
        return sound_list[file_name]


def play_sound(sound):
    '''Plays a sound, if pygame.mixer has been initialized'''
    if mixer.get_init() and sound:
        sound.play()

def play_music(file_name):
    '''Plays some music, if pygame.mixer has been initialized.'''
    if mixer.get_init():
        mixer.music.load(file_name)
        mixer.music.play(-1)
    else:
        print "mixer not ready"
    
